<?php

/**
 * 餐厅纠错反馈
 * 
 * @author zhangchao
 * @since 2012-04-20
 */

include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	//页码
	cgi::both($g_cgival["p"], "p", 1);
	$g_cgival["p"] = intval($g_cgival["p"]);
	
	//长度
	cgi::both($g_cgival["pc"], "pc", 16);
	$g_cgival["pc"] = intval($g_cgival["pc"]);
	
	cgi::both($g_cgival["verify"], "verify", 0);	// status对应着web_rstrt_error的status字段
	$g_cgival["verify"] = intval($g_cgival["verify"]);
	if($g_cgival["verify"] < 0)
	{
		$g_cgival["verify"] = 0;
	}
}

function get_data()
{
	global $g_cgival, $g_pro, $g_show,$config;

	$site_id = admin::admin_get_user_site_id();
	
	$db_web_rstrt = new db_web_rstrt();
	$db_web_rstrt_error = new db_web_rstrt_error();
	if($g_cgival["verify"] == 0)
	{
		$status = array(0);
	}
	else
	{
		$status = array(1,2);
	}
	$list = $db_web_rstrt_error->admin_get_error_list(0,$status,$g_cgival["p"],$g_cgival["pc"]);
	foreach ($list as &$value) {
		$infos = $db_web_rstrt->admin_get_rstrt_by_ids(array($value['res_id']));
		if(!empty($infos[0]))
		{
			$rstrt_info = $infos[0];
			// 跳转到前台的url
			$user_global_config =  user_global_config::get_instance();
			$domain = $user_global_config->get_domain_by_site_id($rstrt_info["site_id"]);
			$rstrt_info["rstrt_url"] = "http://{$domain}/explore/res-{$rstrt_info["RstrtID"]}.html";
			
			$value['rstrt_info'] = $rstrt_info;
		}
		else
		{
			$value['rstrt_info'] = array();
		}
	}
	$g_show['data']['data_list'] = $list;
	$g_show['data']['count'] = $db_web_rstrt_error->admin_get_error_list_count(0,$status);
	
	// 分页
	$max_page = page_bar::get_page_max($g_show['data']['count'], $g_cgival["pc"], $g_cgival["p"]);
	$page_bar_style = array(
			"curt"		=> $g_cgival["p"],
			"max"		=> $max_page,
			"key"		=> "p",
	);
	
	$g_show["page_bar"] = "<b>{$g_show['data']['count']}</b> 条记录&nbsp;&nbsp;第{$g_cgival["p"]}页&nbsp;共{$max_page}页&nbsp;" . page_bar::bar3($page_bar_style);
	
	
	//当前参数输出到页面	
	$g_show['args'] = $g_cgival;
}

$g_show["error"] = 0;
$g_show["errmsg"] = '';
try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/album_list.php");
	check_cgi_pro();
	get_data();
	$g_show["error"] = 0;
	$g_show["errmsg"] = '';
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	if(isset($_GET['debug']))
		print_r($g_show);
	
	$smarty = p_get_smarty ();
	$smarty->assign ( 'g_show', $g_show );
	if ($g_show["error"] == 1)
	{
		$smarty->display("admin_error.html");
		return;
	}
	if($g_cgival["verify"] == 0)
	{
		$smarty->display ( "foodv2/rstrt/rstrt_error.html" );
	}
	else
	{
		$smarty->display ( "foodv2/rstrt/rstrt_error_ed.html" );
	}
}

?>